home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 September / Chip_2001-09_cd1.bin / sharewar / webscrip / webscripter4s.exe / {app} / Includes / jsCookie.ob < prev    next >
Encoding:
Text File  |  2001-07-11  |  2.1 KB  |  84 lines

  1. //begin_lib <!-- Begin External JavaScript -- DO NOT REMOVE THIS LINE -->
  2. var c_exp = new Date();
  3.  
  4. function jsCookie(){
  5. this.Cookies = new Array();
  6. this.Temporary = true;
  7. this.SetExpiration = c_setExpiration;
  8. this.CookiePath = "";
  9. this.CookieDomain = "";
  10. this.Secure = false;
  11. this.SetCookie = c_SetCookie;
  12. this.GetCookies = c_GetCookies;
  13. this.GetValue = c_GetValue;
  14. this.DeleteCookie = c_DelCookie;
  15. }
  16.  
  17. function c_setExpiration(mil){
  18. this.Temporary = false;
  19. var s = c_exp.getTime();
  20.      if(mil){
  21.      c_exp.setTime(mil+s);
  22.      }else{
  23.      c_exp.setTime(s+(365*24*3600*1000));
  24.      }
  25. }
  26.  
  27. function c_SetCookie(name,value){
  28. var cooky = name+"="+escape(value);
  29. cooky += (!this.Temporary) ? "; expires="+c_exp.toGMTString() : "";
  30. cooky += (this.CookiePath!="") ? "; path="+this.CookiePath : "";
  31. cooky += (this.CookieDomain!="") ? "; domain="+this.CookieDomain : "";
  32. cooky += (this.Secure) ?  "; secure" : "";
  33. document.cookie = cooky;
  34. }
  35.  
  36. function c_GetCookies(){
  37. var c = unescape(document.cookie);
  38. var b=0; var i = 0; var l = c.length;var sc=0;
  39. var name="";var value="";var aname="";
  40. var temp = new Array();
  41.           while(i <= l){
  42.           i = c.indexOf("=",b);
  43.               if(i != -1){
  44.             name = Trim(c.substring(b,i));
  45.             sc = c.indexOf(";",i);
  46.             value = (sc!=-1) ? Trim(c.substring(i+1,sc)) : Trim(c.substring(i+1,l));
  47.             var cnt = temp.length;
  48.             temp[cnt] = new Array();
  49.             temp[cnt].name = name;
  50.             temp[cnt].value = value;
  51.             b=(sc==-1) ? l : sc+1;
  52.             }else{
  53.             i=l+1;
  54.             }
  55.         }
  56. this.Cookies = temp;
  57. delete temp;
  58. }
  59.  
  60. function c_GetValue(name){
  61. var r = "";
  62.      for(var i = 0; i < this.Cookies.length; i++){
  63.               if(this.Cookies[i].name==name){
  64.              r = this.Cookies[i].value;
  65.              break;
  66.              }
  67.     }
  68. return r;
  69. }
  70.  
  71. function Trim(str){
  72. return (str.substring(0,1)==" ") ? str.substring(1,str.length) : str;
  73. }
  74.  
  75. function c_DelCookie(name,path,domain,secure){
  76. var cooky = name+"="+"; expires=Fri, 31 Dec 1999 23:59:59 GMT";
  77. cooky += (path) ? "; path="+path : "";
  78. cooky += (domain) ? "; domain="+domain : "";
  79. cooky += (secure) ? "; secure" : "";
  80. document.cookie = cooky;
  81. }
  82.  
  83. //end_lib <!-- End External JavaScript -- DO NOT REMOVE THIS LINE -->
  84.